package com.cnc.service.Impl;

import com.cnc.dao.Impl.StudentDaoImpl;
import com.cnc.dao.StudentDao;
import com.cnc.entity.Student;
import com.cnc.service.StudentService;
import com.cnc.utils.PageUtil;
import com.cnc.utils.ResourceUtil;
import com.cnc.utils.SearchUtil;
import org.junit.Test;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    StudentDao studentDao = new StudentDaoImpl();

    public List<Student> getAllStudent() {
        return studentDao.getAllStudent();
    }

    public boolean deleteStudent(int id) {
        return studentDao.deleteStudent(id) != 0;
    }

    public boolean insertStudent(Student s) {
        return studentDao.insertStudent(s) != 0;
    }

    public boolean updateStudent(int Sid, String field, String value) {
        return studentDao.updateStudent(Sid, field, value) != 0;
    }

    @Override
    public int getCountRows(SearchUtil su) {
        return studentDao.getCountRows(su);
    }

    @Override
    public List<Student> getStudentByPage(PageUtil pu) {
        return studentDao.getStudentByPage(pu);
    }

    public List<Student> searchStudent(SearchUtil su, PageUtil pu){
        return studentDao.searchStudent(su,pu);
    }

    @Override
    public int getMaxId() {
        return studentDao.getMaxId();
    }

    @Override
    public Student getStudentBySid(String sid) {
        return studentDao.getStudentBySid(Integer.parseInt(sid));
    }

    @Override
    public boolean editStudent(Student s) {
        return studentDao.editStudent(s)!=0;
    }
    @Test
    public void te(){
        SearchUtil su = new SearchUtil("中", null, null, null);
        int countRows = getCountRows(su);
        System.out.println(countRows);
        PageUtil pu = new PageUtil("1", ResourceUtil.getRows(), countRows);
        searchStudent(su,pu).forEach(System.out::println);
    }
}
